import {BaseManager} from "db://assets/scripts/framework/BaseManager";
import Message from "db://assets/scripts/framework/Message";
import {MessageType} from "db://assets/scripts/framework/MessageType";

/**
 * 消息中心
 */
export class MessageCenter {
    /**
     * 所有消息管理器
     */
    static managers: BaseManager[] = [];

    /**
     * 发送消息
     *
     * @param message 消息
     */
    static sendMessage(message: Message) {
        for (let manager of this.managers) {
            manager.receiveMessage(message);
        }
    }

    /**
     * 发送消息
     *
     * @param type 消息类型
     * @param command 指令
     * @param content 参数
     */
    static sendCustomMessage(type: MessageType, command: number, content: any) {
        let message = new Message(type, command, content);
        for (let manager of this.managers) {
            manager.receiveMessage(message);
        }
    }
}